package PACKAGE_NAME;

import service.ProductService;
import service.SeckillService;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(40);

        // 模拟查询操作
        for (int i = 0; i < 40; i++) {
            executor.submit(() -> {
                try {
                    new ProductService().queryProduct("beijing", 1L);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }

        // 模拟购买操作
        for (int i = 0; i < 40; i++) {
            executor.submit(() -> {
                try {
                    new ProductService().purchaseProduct(1L, 1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }

        // 模拟秒杀操作
        for (int i = 0; i < 400; i++) {
            executor.submit(() -> {
                try {
                    new SeckillService().seckillProduct(1L, 1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }

        executor.shutdown();
    }
}